<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{$title}</title>
<link rel="stylesheet" href="Res/boot/css/bootstrap.min.css" type="text/css" media="screen" />
<script type="text/javascript" src="Res/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="Res/js/jquery.cookie.js"></script>
<link rel="stylesheet" href="Res/css/global.css" type="text/css" />
</head>

<body>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12 panel panel-info">  
            <span class="cp_title">{$title}</span>
            <div class="add_cp">
                    <a href="index.php?c={$class}&m=view">+返回{$title}列表</a>
            </div>        
            <div class="table_con form-horizontal" style="margin: 0 auto;text-align: center;">               
                <div class="form-group">
                    <label class="col-sm-2 control-label">标题名称：</label>
                    <div class="col-sm-5">
                        <select class="form-control" id="tid" name="tid">
                            <option value="0">选择标题</option>
                            {foreach from=$tdata item=row}
                            {if $cookie.tid eq $row.tid}
                            <option value="{$row.tid}" data-bind="{$row.url}" selected="true">{$row.tname}</option>
                            {else}
                            <option value="{$row.tid}" data-bind="{$row.url}">{$row.tname}</option>
                            {/if}
                            {/foreach}
                        </select>
                    </div>
                </div>    
                <div class="form-group">
                    <label class="col-sm-2 control-label">标题URL：</label>
                    <div class="col-sm-5">
                        <input type="text" readonly="true"  value="{$cookie.url}" autofocus="autofocus" required="required" 
                               class="form-control" autocomplete="on" id="url" name="url" placeholder="标题URL" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">分析：</label>
                    <div class="col-sm-5">
                        <input type="button" class="btn btn-primary" id="btn_fx" value="分析"/>
                        <input type="button" class="btn btn-primary" id="btn_auto_fx" value="自动分析"/>
                        <input type="button" class="btn btn-primary" id="btn_auto_fx_stop" value="停止分析"/>
                        <input type="button" class="btn btn-primary" id="btn_tfx" value="替换分析"/>
                        <input type="button" class="btn btn-success" id="btn_open_close" value="打开/关闭"/>
                        <input type="hidden" value="0" id="htag" />
                    </div>                    
                </div>                    
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-5">
                        <div id="fx_result">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{literal}
<script>    
$(function(){  
    $("#btn_open_close").click(function(){
        $("#fx_result .panel").toggle();
    });    
    $("#tid").change(function(){
        var _this = $(this);
        var url = _this.find("option:selected").attr("data-bind");
        $("#url").val(url);
    });
    var setval = null;
    $("#btn_auto_fx_stop").click(function(){
        clearInterval(setval);
        $("#btn_auto_fx").val("自动分析").attr("disabled", false);
    });
    $("#btn_auto_fx").click(function(){
        var url = $("#url").val();
        if(url !== '') {  
            $("#btn_auto_fx").val("自动分析中...").attr("disabled", true);
            var tag = $("#htag").val();
            if(tag == 1) {
                clearInterval(setval);
            } else {
                setval = setInterval(function(){
                    fx();
                }, 3000);
            }      
        } else {
            alert('请选择标题');
            $("#url").attr("placeholder", '点击选择主题');
        }
    });
    $("#btn_fx").click(function(){
        var url = $("#url").val();        
        if(url !== '') {
            fx();
        } else {
            alert('请选择标题');
            $("#url").attr("placeholder", '点击选择主题');
        }
    });
});
function fx(){
    var tag = $("#htag").val();
    if(tag == 1) {
        return;
    }
    $("#htag").val(1);
    var url = $("#url").val();
    var tid = $("#tid option:selected").val();   
    var btn_txt = $("#btn_fx").val();
    var url_str = 'index.php?c=storycontent&m=fx_tianya';
    var params = new Object();
    params.url = url;
    params.tid = tid;
    params.ajax =1;
    $("#btn_fx").val("分析中...").attr("disabled", true);  
    $.post(url_str, params, function(data){
        if(data.status === 0) {
            $("#htag").val(0);
            if(data.msg.next_url != false) {
                $("#url").val(data.msg.next_url);
            } else {
                $("#url").val('分析已完成');
                $('#btn_auto_fx_stop').trigger("click");
            }
            $("#btn_fx").val('分析下一页').attr("disabled", false);                    
            var result = data.msg.data;
            $("#fx_result").empty();
            $.each(result, function(key, row){
                $("#fx_result").append(row.html);
            });
            $(".panel #paneldiv").on("click",function(){
                var _this = $(this);
                var divid = "panel-" + _this.attr("data-bind");
                var _thisdiv = $("#" + divid);
                var _headdiv = _thisdiv.find("div:eq(0)");
                var _bodydiv = _thisdiv.find("div:eq(1)");
                if(_bodydiv.is(":hidden")) {
                    _bodydiv.slideDown("1000");
                    _headdiv.find("h3 span").removeClass("glyphicon-arrow-up").addClass("glyphicon-arrow-down");
                } else {
                    _bodydiv.slideUp("1000");
                    _headdiv.find("h3 span").removeClass("glyphicon-arrow-down").addClass("glyphicon-arrow-up");
                }
            });
        } else {
            window.alert(data.msg);
            $("#btn_fx_tianya").val(btn_txt).attr("disabled", false);
        }                
    }, 'json');
}
</script>
{/literal}
</script>
</body>
</html>
